package com.xq.service.impl;

import com.xq.entity.UmsUserOrganization;
import com.xq.exception.BusinessException;
import com.xq.mapper.UmsUserOrganizationMapper;
import com.xq.service.IUmsUserOrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xq.vo.DataBaseEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuven
 * @since 2025-05-26
 */
@Service
public class UmsUserOrganizationServiceImpl extends ServiceImpl<UmsUserOrganizationMapper, UmsUserOrganization> implements IUmsUserOrganizationService {

    @Autowired
    private UmsUserOrganizationMapper umsUserOrganizationMapper;

    @Override
    public void updateUserOrganization(String userId, String organizationId) {
        UmsUserOrganization umsUserOrganization = new UmsUserOrganization();
        umsUserOrganization.setUserId(userId);
        umsUserOrganization.setOrgId(organizationId);
        int insert = umsUserOrganizationMapper.insert(umsUserOrganization);
        if (insert <= 0) {
            throw new BusinessException(DataBaseEnum.INSERTION_FAILED);
        }

    }

    @Override
    public void deleteUserOrganization(String userId, String organizationId) {
        int i = umsUserOrganizationMapper.deleteById(new UmsUserOrganization(userId, organizationId));
        if (i <= 0) {
            throw new BusinessException(DataBaseEnum.DELETE_FAILED);
        }
    }

}
